package com.kate.mall.order.price;

import cn.hutool.core.map.MapUtil;
import com.kate.mall.order.dto.OrderDTO;
import com.kate.mall.order.dto.OrderItemDTO;
import com.kate.mall.order.feign.MallFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @Description: 默认的运费计算组件
 * @Auther: 新梦想*陈超
 * @Date: 2021/10/30 19:35
 */
@Component
@Slf4j
public class DefaultFreightCalculator implements FreightCalculator {

	@Resource
	private MallFeignClient mallFeignClient;
	@Override
	public BigDecimal calculate(OrderDTO order, OrderItemDTO orderItem, PromotionActivityResult result) {

		BigDecimal freight = MapUtil.get(mallFeignClient.getFreight(),"freight", BigDecimal.class);
		BigDecimal freightLimit = MapUtil.get(mallFeignClient.getFreightLimit(),"freight_limit", BigDecimal.class);
		BigDecimal payGoodsPrice = order.getGoodsPrice();
		log.info("=====含赠品的运费计算组件，计算参数:运费：{},免运费价：{},商品总价：{}",freight,freightLimit,payGoodsPrice);
		if(payGoodsPrice.compareTo(freightLimit)==-1){
			return freight;
		}

		return new BigDecimal("0.0");
	}




}
